/*
* ========== Copyright Header Begin ==========================================
* 
* OpenSPARC T1 Processor File: breakpoint.h
* Copyright (c) 2006 Sun Microsystems, Inc.  All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES.
* 
* The above named program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License version 2 as published by the Free Software Foundation.
* 
* The above named program is distributed in the hope that it will be 
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
* General Public License for more details.
* 
* You should have received a copy of the GNU General Public
* License along with this work; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
* 
* ========== Copyright Header End ============================================
*/
/*
 * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */

#ifndef	_BREAKPOINT_H_
#define	_BREAKPOINT_H_

#pragma ident	"@(#)breakpoint.h	1.6	05/11/17 SMI"

#ifdef __cplusplus
extern "C" {
#endif

#define	BREAK_HASH_BITS	4
#define	BREAK_HASH_SIZE	(1<<BREAK_HASH_BITS)
#define	BREAK_HASH_MASK	(BREAK_HASH_SIZE-1)


struct BP_INFO {
	breakpoint_t*	hash[BREAK_HASH_SIZE];

	int		next_id;
	breakpoint_t*	free_listp;
	int		active_count;
	breakpoint_t*	active_listp;
	int		disabled_count;
	breakpoint_t*	disabled_listp;

	int		do_step;
	int		on_this;
};

struct BREAKPOINT {
	uint64_t	pc;
	uint32_t	context;
	bool_t		enabled;
	bool_t		first_strike;
	int		id;
	breakpoint_t*	free_nextp;
	breakpoint_t*	active_nextp;
	breakpoint_t*	disabled_nextp;
	breakpoint_t*	hash_nextp;
};


	/*
	 * for the moment use a global to indicate system wide
	 * breakpoints ... will go away when we define multiple
	 * systems.
	 */

typedef enum {
	NOTHING, ON_BREAKPOINT
} breakpoint_check_code_t;


#define	DEFAULT_BP_CONTEXT	0


extern bp_info_t *	system_breakpointsp;


	/* Internal breakpoint manipulation interface */
extern bp_info_t *	breakpoint_init();
extern breakpoint_t *	breakpoint_insert(bp_info_t * bip, tvaddr_t pc, int context);
extern void		breakpoint_insert_next(bp_info_t * bip);
extern void		breakpoint_clear_next(bp_info_t * bip);
extern int		breakpoint_delete_by_id(bp_info_t * bip, int id);
extern breakpoint_t *	breakpoint_find_by_addr(bp_info_t * bip, uint64_t addr, int context);
extern int		breakpoint_delete_by_addr(bp_info_t * bip, uint64_t addr, int context);
extern int		breakpoint_disable_by_id(bp_info_t * bip, int id);
extern int		breakpoint_enable_by_id(bp_info_t * bip, int id);
extern bool_t		breakpoint_any_reached(void);




	/* Blaze UI calls for breakpoint stuff */
extern bool_t		breakpoint_parse_command(bp_info_t * bip, char* args, char* stage_name /* default: NULL */);
extern void		breakpoint_print(bp_info_t *);
extern bool_t		breakpoint_dump(bp_info_t * bip, FILE *fp);
extern bp_info_t *	breakpoint_restore(FILE * fp);

extern breakpoint_check_code_t breakpoint_check(bp_info_t * bip, uint64_t pc, int context, breakpoint_t ** bpp);


#ifdef __cplusplus
}
#endif

#endif	/* !_BREAKPOINT_H_ */
